/**
 * @license
 * Copyright 2024 The Model Explorer Authors. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ==============================================================================
 */

:host {
  position: relative;
  width: 370px;
  min-width: 370px;
  line-height: normal;
}

.container {
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  border-left: 1px solid var(--me-outline-hairline-color);
  color: var(--me-on-surface-color);
  background-color: var(--me-surface-color);
  overflow-y: auto;
  position: relative;

  .section {
    transition: max-height 150ms ease-out;
    padding-bottom: 8px;
    box-sizing: border-box;

    &.collapsed {
      /* stylelint-disable-next-line declaration-no-important -- override element style */
      max-height: 32px !important;
      overflow: hidden;
    }

    &.inputs {
      padding-bottom: 16px;
    }

    .flat-items-container {
      display: flex;
      flex-direction: column;
      margin-top: 10px;
      gap: 8px;
    }

    .flat-item {
      display: flex;
      flex-direction: column;
      padding: 0 2px 0 12px;

      .name-row {
        display: flex;
        align-items: center;

        &.search-match {
          background-color: var(--me-search-results-highlight-color);
        }

        .index {
          color: var(--me-on-surface-variant-color);
          min-width: 14px;
          margin-right: 2px;
        }

        .name {
          color: var(--me-primary-color);
          font-weight: 500;
          display: flex;
          align-items: center;

          &.locator {
            flex-grow: 1;
            display: flex;
            align-items: center;
            cursor: pointer;
            line-break: anywhere;

            &:hover {
              background-color: var(--me-surface-container-high-color);

              .locator-icon-container {
                opacity: 0.8;
              }
            }
          }
        }
      }

      .target-op-container {
        display: flex;
        align-items: center;
        color: var(--me-on-surface-low-color);
        font-weight: normal;

        mat-icon.arrow {
          margin: 0 4px;
        }
      }

      .source-op-node-label {
        color: var(--me-on-surface-variant-color);
        font-weight: normal;
        margin-left: 6px;
      }

      .metadata-table {
        margin-top: 3px;
        margin-left: 18px;
        margin-right: 0;
      }
    }

    .node-id-attribute {
      display: flex;
      cursor: pointer;
    }
  }

  .section:not(:first-child) {
    border-top: 1px solid var(--me-outline-hairline-color);
  }

  .filler {
    flex-grow: 1;
  }

  .header {
    display: flex;
    align-items: center;
    font-weight: 700;
    padding: 4px 12px 0;
    text-transform: uppercase;
    position: sticky;
    top: 0;
    z-index: 100;
    flex-shrink: 0;
    box-sizing: border-box;
    color: var(--me-on-surface-color);
    background-color: var(--me-surface-color);
    user-select: none;

    &.input,
    &.output,
    &.identical-groups {
      justify-content: space-between;
    }

    .header-label-container {
      display: flex;
      align-items: center;
    }

    button.toggle {
      padding: 0;
      width: 24px;
      height: 24px;
      margin-left: -8px;
      margin-right: 2px;
      display: flex;
      align-items: center;
      justify-content: center;

      mat-icon {
        color: inherit;
        font-size: 20px;
        width: 20px;
        height: 20px;
      }

      &:hover {
        background-color: var(--me-surface-container-high-color);
      }

      ::ng-deep .mat-mdc-button-touch-target {
        display: none;
      }
    }
  }

  .metadata-table {
    border-spacing: 0;
    border-collapse: collapse;
    margin: 0 12px;
    word-break: break-all;
    max-width: calc(100% - 28px);

    &.info-attrs {
      margin-left: 30px;
    }

    tr {
      vertical-align: text-top;

      &.search-match {
        background-color: var(--me-search-results-highlight-color);
      }

      &:hover.has-hover-values {
        cursor: pointer;
        background-color: var(--me-surface-container-low-color);
      }

      mat-icon.bullet {
        flex-shrink: 0;
        font-size: 4px;
        width: 5px;
        height: 5px;
        color: var(--me-on-surface-low-color);
        margin-right: 4px;
        margin-top: 6px;
      }
    }

    td.key {
      color: var(--me-on-surface-low-color);
      padding-right: 6px;
      white-space: nowrap;
      min-width: 100px;
      width: 100px;
      max-width: 100px;
      overflow: hidden;
      text-overflow: ellipsis;
      position: relative;

      .key-container {
        display: flex;
        align-items: flex-start;
        overflow: hidden;
        position: absolute;
        inset: 0;
      }
    }

    td.value {
      max-width: 10px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;

      &:has(expandable-info-text.expanded) {
        white-space: normal;
        max-width: inherit;
      }
    }

    .target-node-container {
      display: flex;
      align-items: center;
      cursor: pointer;

      &:hover .locator-icon-container {
        opacity: 0.8;
      }

      &.search-match {
        background-color: var(--me-search-results-highlight-color);
      }
    }

    .values-hover-trigger {
      box-sizing: border-box;
      border-radius: 99px;
      display: flex;
      align-items: center;
      background-color: var(--me-secondary-container-color);
      color: var(--me-on-secondary-container-color);
      width: fit-content;
      height: 16px;
      padding: 0 6px;
      font-size: 10px;
    }
  }

  .items-container {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: 10px;
    margin-bottom: 6px;
  }

  .locator-icon-container {
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.7;
    margin-left: 4px;

    &.left {
      margin-right: 4px;
      margin-left: 0;
      display: inline-block;

      mat-icon {
        margin-bottom: -2px;
      }
    }

    &:hover {
      opacity: 0.85;
    }

    mat-icon {
      color: var(--me-on-surface-variant-color);
    }
  }

  .visibility-icon-container {
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.5;
    padding: 0 11px 0 20px;
    cursor: pointer;

    &:hover {
      opacity: 0.8;
    }

    mat-icon {
      color: var(--me-on-surface-variant-color);
      font-size: 14px;
      width: 14px;
      height: 14px;
    }

    &.input.visible {
      mat-icon {
        color: var(--me-incoming-edge-color);
      }
    }

    &.output.visible {
      mat-icon {
        color: var(--me-outgoing-edge-color);
      }
    }
  }

  ::ng-deep {
    a,
    a:visited {
      /* stylelint-disable-next-line declaration-no-important -- override MDC */
      color: var(--me-link-color) !important;
    }
  }
}

.resizer {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 6px;
  cursor: ew-resize;
  background-color: transparent;
  z-index: 200;

  &:hover,
  &.resizing {
    background-color: var(--me-surface-container-low-color);
  }
}

.hide-toggle {
  position: absolute;
  right: 100%;
  bottom: 2px;
  width: 16px;
  height: 20px;
  border: 1px solid var(--me-outline-variant-color);
  border-right: none;
  box-sizing: border-box;
  border-radius: 99px;
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
  cursor: pointer;
  background-color: var(--me-surface-container-lowest-color);

  &:hover {
    background-color: var(--me-surface-container-low-color);
  }

  mat-icon {
    width: 18px;
    height: 18px;
    font-size: 18px;
    color: var(--me-on-surface-variant-color);
  }
}

::ng-deep bubble-container:has(.model-explorer-const-values-popup) {
  width: 100%;
}

::ng-deep .model-explorer-const-values-popup {
  padding: 8px;
  line-height: 12px;
  color: var(--me-on-surface-color);
  background-color: var(--me-surface-container-low-color);

  .values-count-msg {
    margin-bottom: 8px;
    color: var(--me-on-surface-low-color);
    font-size: 12px;
  }

  .content {
    font-size: 11px;
    white-space: pre-wrap;
    font-family: monospace;
  }

  .namespace-row {
    font-size: 12px;
    padding: 3px 0;
  }
}
